package com.anycl.security.configuration;


import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.security.authentication.AuthenticationDetailsSource;
import org.springframework.security.web.authentication.WebAuthenticationDetails;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class MyWebAuthenticationDetails extends WebAuthenticationDetails{

    private boolean imageCodeIsRight;

    public boolean isImageCodeIsRight() {
        return imageCodeIsRight;
    }

    public MyWebAuthenticationDetails(HttpServletRequest request) {
        super(request);
        String requestCode = request.getParameter("kaptcha");
        HttpSession session = request.getSession();
        String saveCode = (String) session.getAttribute("kaptcha");
        if (!StringUtils.isEmpty(saveCode)) {
            session.removeAttribute("kaptcha");

            if (!StringUtils.isEmpty(requestCode) && requestCode.equals(saveCode)) {
                this.imageCodeIsRight = true;
            }
        }
    }


}
